package com.wu.vpdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import com.wu.vpdemo.databinding.ActivityMainBinding;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


    ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        initView();
    }

    private void initView() {
        processFullScreen();
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(VideoFragment.newInstance(1));
        fragments.add(VideoFragment.newInstance(1));
//        fragments.add(VideoFragment.newInstance(2));
//        fragments.add(VideoFragment.newInstance(2));
        fragments.add(ImageViewFragment.newInstance(2));
        fragments.add(ImageViewFragment.newInstance(1));
        fragments.add(ImageViewFragment.newInstance(1));
        fragments.add(ImageViewFragment.newInstance(2));
        fragments.add(ImageViewFragment.newInstance(1));
        fragments.add(ImageViewFragment.newInstance(2));
        fragments.add(ImageViewFragment.newInstance(1));
        fragments.add(ImageViewFragment.newInstance(2));
        fragments.add(ImageViewFragment.newInstance(1));
        fragments.add(ImageViewFragment.newInstance(2));
        fragments.add(ImageViewFragment.newInstance(1));
        fragments.add(ImageViewFragment.newInstance(2));
        fragments.add(ImageViewFragment.newInstance(2));
        fragments.add(ImageViewFragment.newInstance(2));
//        fragments.add(ImageViewFragment.newInstance(1));
        FragmentAdapter mAdapter = new FragmentAdapter(this, fragments);

        binding.vpContent.setAdapter(mAdapter);
    }


    /**
     * 处理刘海屏全屏问题
     */
    public void processFullScreen() {
        setTransparentForWindow(this);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            lp.layoutInDisplayCutoutMode =
                    WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
        }
        getWindow().setAttributes(lp);
        // 设置页面全屏显示
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

    }

    /**
     * 设置透明
     */
    public static void setTransparentForWindow(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
            activity.getWindow()
                    .getDecorView()
                    .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            activity.getWindow()
                    .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }
}